SET(GEOMMATH_LIB_FILE ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}GeomMath${CMAKE_STATIC_LIBRARY_SUFFIX})
IF(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Windows")
    SET(ISPC_COMPILER_PATH ${PROJECT_SOURCE_DIR}/External/Windows/bin/)
    SET(ISPC_COMPILER ispc.exe)
    IF(NOT ${CMAKE_CROSSCOMPILING})
        if(${ARCH_BIT} MATCHES 64)
            SET(ISPC_OPTIONS --arch=x86-64 --target=host)
            SET(CMAKE_AR lib)
            SET(ISPC_LIBRARIAN_OPTIONS /MACHINE:X64 /OUT:${GEOMMATH_LIB_FILE})
        else()
            SET(ISPC_OPTIONS --arch=x86 --target=host)
            SET(CMAKE_AR lib)
            SET(ISPC_LIBRARIAN_OPTIONS /MACHINE:X86 /OUT:${GEOMMATH_LIB_FILE})
        endif()
    ELSE()
        if(PSP2)
            SET(ISPC_OPTIONS --arch=arm --cpu=cortex-a9 --target=neon-i32x4)
            SET(CMAKE_AR ${SNC_TOOLCHAIN_DIR}psp2snarl -rcv ${GEOMMATH_LIB_FILE})
        endif()
    ENDIF()
ELSEIF(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
    SET(ISPC_COMPILER_PATH ${PROJECT_SOURCE_DIR}/External/Darwin/bin/)
    SET(ISPC_COMPILER ispc)
    SET(ISPC_OPTIONS --arch=x86-64)
    SET(ISPC_LIBRARIAN_OPTIONS -rcv ${GEOMMATH_LIB_FILE})
ELSEIF(${CMAKE_HOST_SYSTEM_NAME} MATCHES "FreeBSD")
    SET(ISPC_COMPILER_PATH ${PROJECT_SOURCE_DIR}/External/FreeBSD/bin/)
    SET(ISPC_COMPILER ispc)
    SET(ISPC_OPTIONS --arch=x86-64)
    SET(ISPC_LIBRARIAN_OPTIONS -rcv ${GEOMMATH_LIB_FILE})
ELSE()
    SET(ISPC_COMPILER_PATH ${PROJECT_SOURCE_DIR}/External/Linux/bin/)
    SET(ISPC_COMPILER ispc)
    SET(ISPC_OPTIONS --arch=x86-64)
    SET(ISPC_LIBRARIAN_OPTIONS -rcv -o ${GEOMMATH_LIB_FILE})
ENDIF(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Windows")

# override ISPC_OPTIONS if build for android
IF(${CMAKE_SYSTEM_NAME} MATCHES "Android")
    SET(LLVM_COMPILER_PATH ${ISPC_COMPILER_PATH})
    SET(ISPC_COMPILER_PATH ${PROJECT_SOURCE_DIR}/External/Android/bin/)
    SET(ISPC_OPTIONS --arch=arm --cpu=cortex-a9 --target=neon-i32x4)
ENDIF()

SET(ISPC_OPTIONS ${ISPC_OPTIONS} -O2)

SET(GEOMMATH_LIB_HEADER_FOLDER ${CMAKE_CURRENT_BINARY_DIR})
message(status "GEOMMATH_LIB_HEADER_FOLDER " ${GEOMMATH_LIB_HEADER_FOLDER})

add_library(GeomMath STATIC IMPORTED GLOBAL)
add_dependencies(GeomMath GeomMathLib)

set_target_properties(GeomMath
        PROPERTIES
        IMPORTED_LOCATION ${GEOMMATH_LIB_FILE}
        INTERFACE_INCLUDE_DIRECTORIES ${GEOMMATH_LIB_HEADER_FOLDER}
        )

add_subdirectory(ispc)

